const state = {
  userAccount: '',
  loginState: false,
  userPower: 0,
  userID: -1
}

const getters = {
  loginState: (state, getters, rootState) => {
    return state.loginState
  },
  userAccount: (state, getters, rootState) => {
    if (state.loginState) return state.userAccount
    else return ''
  },
  userPower: (state, getters, rootState) => {
    if (state.loginState) return state.userPower
    else return 0
  },
  userID: (state, getters, rootState) => {
    if (state.loginState) return state.userID
    else return -1
  }
}

const mutations = {
  login (state, user) {
    state.userAccount = user.userAccount
    state.loginState = true
    state.userPower = user.userPower
    state.userID = user.userID
  },
  logout (state) {
    state.userAccount = ''
    state.loginState = false
    state.userPower = ''
    state.userID = -1
  },
  setPower (state, power) {
    state.userPower = power
  }
}

export default {
  state,
  getters,
  mutations
}
